package com.example.mybaisplus1.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybaisplus1.entity.Dept;
import com.example.mybaisplus1.service.IDeptService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuyongli
 * @since 2022-12-28
 */
@RestController
@CrossOrigin
@RequestMapping("/dept")
public class DeptController {
    @Resource
    private IDeptService deptService;

    // 获取所有数据
    @GetMapping("deptlike")
    public List<Dept> getAll(){
        // 查询id like "%1%"
        QueryWrapper queryWrapper = new QueryWrapper();
        // 匹配查找到id=1的数据
        queryWrapper.like("deptno","1");
        return deptService.list(queryWrapper);
    }

    // 分页
    @GetMapping("page")
    public IPage getAll1(Integer curr,Integer size){
        // 1当前页     3代表每页显示多少条数据
        IPage page = new Page(curr,size);
        return deptService.page(page);
    }

    @GetMapping("All")
    public List<Dept> getAll3(){
        // 匹配查找到id=1的数据
        return deptService.list();
    }


}

